package com.py.credit.service.impl;

import com.py.credit.common.Page;
import com.py.credit.common.ServiceException;
import com.py.credit.dao.RetrospectiveDao;
import com.py.credit.service.RetrospectiveService;
import com.py.credit.utils.SQLBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

@Service
public class RetrospectiveServiceImpl implements RetrospectiveService {

    @Autowired
    private RetrospectiveDao retrospectiveDao;

    @Override
    public List<Map<String, Object>> getByConditionForPage(List<String> showColumns, String[] additionalColumns, String condition, Page page) {
        if (CollectionUtils.isEmpty(showColumns)) {
            throw new ServiceException("至少选择一列");
        }
        List<String> conditions = SQLBuilder.createConditionSql(condition);

        return retrospectiveDao.selectByConditionForPage(showColumns, additionalColumns, conditions, page);
    }

    @Override
    public Map<String, Object> getDetail(String id) {
        return retrospectiveDao.selectDetail(id);
    }
}
